package com.xiaoxu.spzx.product.controller;


import com.xiaoxu.spzx.model.entity.product.Category;
import com.xiaoxu.spzx.model.entity.product.ProductSku;
import com.xiaoxu.spzx.model.vo.common.Result;
import com.xiaoxu.spzx.model.vo.common.ResultCodeEnum;
import com.xiaoxu.spzx.model.vo.h5.IndexVo;
import com.xiaoxu.spzx.product.service.CategoryService;
import com.xiaoxu.spzx.product.service.ProductService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "首页接口管理")
@RestController
@RequestMapping(value="/api/product/index")
//@CrossOrigin //跨域 GateWay解决 不能 再写一个 Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductService productService;

    @GetMapping
    public Result index(){
        //1. 所有的一级分类
        List<Category> categoryList =  categoryService.selectOneCategory();


        //2.根据销量排序前十条记录

          List<ProductSku> productSkuList =  productService.selectProductSkuBysal();
        // 3. 封装数据
        IndexVo indexVo = new IndexVo();
        indexVo.setCategoryList(categoryList);
        indexVo.setProductSkuList(productSkuList);

        return Result.build(indexVo, ResultCodeEnum.SUCCESS);

    }

}
